package com.yx.ehis.system;

import org.eclipse.swt.SWT;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
import org.eclipse.ui.application.WorkbenchWindowAdvisor;
import org.eclipse.wb.swt.ResourceManager;
import org.eclipse.wb.swt.SWTResourceManager;

import com.yx.system.model.Context;
import com.yx.system.util.SystemTools;

public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
	public ApplicationWorkbenchWindowAdvisor(
			IWorkbenchWindowConfigurer configurer) {
		super(configurer);
	}

	@Override
	public ActionBarAdvisor createActionBarAdvisor(
			IActionBarConfigurer configurer) {
		return new ApplicationActionBarAdvisor(configurer);
	}

	@Override
	public void preWindowOpen() {
		IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
		// 显示工具条
		configurer.setShowCoolBar(true);
		// 显示菜单条
		configurer.setShowMenuBar(true);
		// 显示状态线
		configurer.setShowStatusLine(true);
		// 只能用最小化和关闭
		configurer.setShellStyle(SWT.MIN | SWT.CLOSE);
	}

	@Override
	public void postWindowOpen() {
		IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
		// 窗口初始为最大化
		configurer.getWindow().getShell().setMaximized(true);
		configurer
				.getActionBarConfigurer()
				.getStatusLineManager()
				.setMessage(SystemTools.getImage("icons/tip.png"),
						"欢迎使用" + Context.getInstance().getProductName());
	}

	@Override
	public void dispose() {
		SWTResourceManager.dispose();
		ResourceManager.dispose();
		super.dispose();
	}
}
